
import administratorAccount.*;
import org.hibernate.*;
import java.util.*;
import p.*;

public class AdminTest{
	
	public AttendenceInfo feedAttendenceInfo(int size,Employee em){
		AttendenceInfo ai=new AttendenceInfo();
		ai.setEmployee(em);
		Set tc=new TreeSet();
		for(int i=0;i < size;i++){
			Pair pair=feedAttendenceRecord();
			tc.add(pair.getSecond());
		}
		ai.setRecords(tc);
		System.out.println("------------------------------------------------------------------------\n"+
						   "AttendenceInfo created: \n"+
						   "With recordNumber: "+ai.getRecordNumber()+"\n"+
						   "With timesLate: "+ai.getTimesLate()+"\n"+
						   "With timesAskingForLeave: "+ai.getTimesAskingForLeave()+"\n"+
						   "With timesAbsent: "+ai.getTimesAbsent()+"\n"+
						   "With timesOnTime: "+ai.getTimesOnTime()+"\n"+
						   "With totalTimes: "+(ai.getTimesAbsent()+ai.getTimesAskingForLeave()+ai.getTimesLate()+ai.getTimesOnTime())+"\n"+
						   "With ratesLate: "+ai.getRateOfLate()+"\n"+
						   "With ratesAbsent: "+ai.getRateOfAbsent()+"\n"+
						   "With ratesAskingForLeave: "+ai.getRateAskingForLeaving()+"\n"+
						   "With ratesOnTime: "+ai.getRateOnTime()+"\n"+
						   "With totalRates: "+(ai.getRateAskingForLeaving()+ai.getRateOfAbsent()+ai.getRateOfLate()+ai.getRateOnTime())+"\n"+
						   "------------------------------------------------------------------------\n");
		return ai;
	}
	
	public Pair feedAttendenceRecord(){
		AttendenceRecord rec=new AttendenceRecord();
		Date dat=TestCommon.getDateIncre();
		rec.setDate(dat);
		int i=TestCommon.getRandom().nextInt(4);
		switch (i){
		case 0:
			rec.setType(AttendenceRecord.Type.getAbsent().toString());
			break;
		case 1:
			rec.setType(AttendenceRecord.Type.getAskingforleave().toString());
			break;
		case 2:
			rec.setType(AttendenceRecord.Type.getOntime().toString());
			break;
		default:
			rec.setType(AttendenceRecord.Type.getLate().toString());
		}
		System.out.println("#########################\n"+
						   "AttendenceRecord created: \n"+
						   "With state: "+rec.getType().toString()+"\n"+
						   "#########################\n");
		return new Pair(dat,rec);
	}
	
	public EmployeeInfo feedEmployeeInfo(Employee em){
		EmployeeInfo ei=new EmployeeInfo();
		ei.setEmployee(em);
		ei.setAddress(TestCommon.getRandomAddress().toString());
		ei.setAge(TestCommon.getRandom().nextInt());
		ei.setBackupPassword(TestCommon.getRandomStr(20));
		ei.setBirthday(TestCommon.getRandomDate());
		ei.setFirstName(TestCommon.getRandomStr(10));
		ei.setMiddleName(TestCommon.getRandomStr(10));
		ei.setLastName(TestCommon.getRandomStr(10));
		ei.setPassword(TestCommon.getRandomStr(20));
		ei.setSex(TestCommon.getRandom().nextBoolean());
		ei.setUserName(TestCommon.getRandomStr(10));
		ei.setTelNumber1(TestCommon.getTelNumber().toString());
		ei.setTelNumber3(TestCommon.getTelNumber().toString());
		
		System.out.println("------------------------------------------------------------------------\n"+
						   "EmployeeInfo created: \n"+
						   "With address: "+ei.getAddress().toString()+"\n"+
						   "With age: "+ei.getAge()+"\n"+
						   "With BackupPassword: "+ei.getBackupPassword()+"\n"+
						   "With Birthday: "+ei.getBirthday().toGMTString()+"\n"+
						   "With Firstname: "+ei.getFirstName()+"\n"+
						   "With Middlename: "+ei.getMiddleName()+"\n"+
						   "With Lastname: "+ei.getLastName()+"\n"+
						   "With Password: "+ei.getPassword()+"\n"+
						   "With Sex: "+(ei.getSex() ? "Male" : "Female")+"\n"+
						   "With Username: "+ei.getUserName()+"\n"+
						   "With TelNumber1: "+ei.getTelNumber1().toString()+"\n"+
						   "With TelNumber2: "+ei.getTelNumber2().toString()+"\n"+
						   "With TelNumber3: "+ei.getTelNumber3().toString()+"\n"+
						   "With TelNumber4: "+ei.getTelNumber4().toString()+"\n"+
						   "------------------------------------------------------------------------\n");
		return ei;
	}
	
	public Salary feedSalary(Employee em){
		Salary sry=new Salary();
		sry.setEmployee(em);
		sry.setMonthlyPay(TestCommon.getRandom().nextDouble());
		sry.setMonthlyPayUnit(TestCommon.getUnit().toString());
		sry.setYearlyPay(TestCommon.getRandom().nextDouble());
		sry.setYearlyPayUnit(TestCommon.getUnit().toString());
		System.out.println("------------------------------------------------------------------------\n"+
				   		   "Salary created: \n"+
				   		   "With monthlyPay: "+sry.getMonthlyPay()+"\n"+
				   		   "With yearlyPay: "+sry.getYearlyPay()+"\n"+
				   		   "------------------------------------------------------------------------\n");
		return sry;
	}
	
	public Licence feedLicence(int size1,int size2,Employee em){
		System.out.println("------------------------------------------------------------------------\n"+
						   "creating licence: \n");
		
		Licence lic=new Licence();
		lic.setEmployee(em);
		HashSet hs=new HashSet();
		lic.setAppLicenceMapping(hs);
		for(int i=0;i < size1;i++)
		{
			Mapping map=new Mapping();
			hs.add(map);
			HashMap hm=new HashMap();
			map.setCommandMapping(hm);
			int rnd=TestCommon.getRandom().nextInt(3);
			for(int j=0;j < size2;j++)
				hm.put(TestCommon.getRandomStr(10),
					   rnd == 0 ? Mapping.MappingType.getDisabled().toString() :
						        rnd == 1 ? Mapping.MappingType.getEnabled().toString() :
						        Mapping.MappingType.getInvisible().toString());
			map.setEmployee(em);
			map.setAppName(TestCommon.getRandomStr(10));
			
			System.out.println("new command Mapping created for app: "+map.getAppName()+"\n");
			System.out.println(map.getCommandMapping().toString()+"\n");
		}
		
		System.out.println("------------------------------------------------------------------------\n");
		return lic;
	}
	
	public Employee feedEmployee(Class c){
		System.out.println("#########################\n" +
						   "Employee creating: \n");
		
		Employee em=(c == Employee.class ? new Employee() :
					(c == Accountant.class ? new Accountant() :
					(c == SoftwareEngineer.class ? new SoftwareEngineer() :
					(c == Manager.class ? new Manager() :
					new FrontDesk()))));
		em.setAttendence(feedAttendenceInfo(TestCommon.getRandom().nextInt(50),em));
		em.setInfo(feedEmployeeInfo(em));
		em.setLicence(feedLicence(TestCommon.getRandom().nextInt(5),TestCommon.getRandom().nextInt(5),em));
		
		System.out.println("Employee creation finished\n"+
						   "##########################\n");
		return em;
	}
}
